package com.lenovo.agricultureServer;

import android.app.Application;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

public class ServerApp extends Application
{
	// 各种传感器最小和最大的默认值
	public static final int MIN_AIR_T = 18;
	public static final int MAX_AIR_T = 25;
	public static final int MIN_AIR_H = 18;
	public static final int MAX_AIR_H = 25;
	public static final int MIN_SOIL_T = 18;
	public static final int MAX_SOIL_T = 25;
	public static final int MIN_SOIL_H = 18;
	public static final int MAX_SOIL_H = 25;

	public static final int MIN_LIGHT = 18;
	public static final int MAX_LIGHT = 25;
	public static final int MIN_CO2 = 18;
	public static final int MAX_CO2 = 25;
	public static final int MAX_PM25 = 500;
	public static final int CONTROL_AUTO = 0; //0表示手动控制，1表示自动控制
	
	/*
	 * SharedPreferences是以键值对来存储应用程序的配置信息的一种方式，
	 * 它只能存储基本数据类型。一个程序的配置文件仅可以在本应用程序中使用，
	 * 或者说只能在同一个包内使用，不能在不同的包之间使用。
	 * 实际上sharedPreferences是采用了XML格式将数据存储到设备中，
	 */
	private SharedPreferences mSharedPreferences;
	
	@Override
	public void onCreate()
	{
		super.onCreate();
		mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
	}
	
	private void saveIntValueToPreferences(String key, int value)
	{
		Editor editor = mSharedPreferences.edit();
		editor.putInt(key, value);
		editor.commit();
	}

	//空气温度最小值
	public int getMinAirTemperature() {
		return mSharedPreferences.getInt("minAirTemperature",MIN_AIR_T);
	}
	public void setMinAirTemperature(int minAirTemperature) {
		saveIntValueToPreferences("minAirTemperature", minAirTemperature);
	}

	//空气温度最大值
	public int getMaxAirTemperature() {
		return mSharedPreferences.getInt("maxAirTemperature",MAX_AIR_T);
	}
	public void setMaxAirTemperature(int maxAirTemperature) {
		saveIntValueToPreferences("maxAirTemperature", maxAirTemperature);
	}

	//空气湿度最小值
	public int getMinAirHumidity() {
		return mSharedPreferences.getInt("minAirHumidity",MIN_AIR_H);
	}
	public void setMinAirHumidity(int minAirHumidity) {
		saveIntValueToPreferences("minAirHumidity", minAirHumidity);
	}

	//空气湿度最大值
	public int getMaxAirHumidity() {
		return mSharedPreferences.getInt("maxAirHumidity",MAX_AIR_H);
	}
	public void setMaxAirHumidity(int maxAirHumidity) {
		saveIntValueToPreferences("maxAirHumidity", maxAirHumidity);
	}

	//土壤温度最小值
	public int getMinEarthTemperature() {
		return mSharedPreferences.getInt("minEarthTemperature",MIN_SOIL_T);
	}
	public void setMinEarthTemperature(int minEarthTemperature) {
		saveIntValueToPreferences("minEarthTemperature", minEarthTemperature);
	}

	//土壤温度最大值
	public int getMaxEarthTemperature() {
		return mSharedPreferences.getInt("maxEarthTemperature",MAX_SOIL_T);
	}
	public void setMaxEarthTemperature(int maxEarthTemperature) {
		saveIntValueToPreferences("maxEarthTemperature", maxEarthTemperature);
	}

	//土壤湿度最小值
	public int getMinEarthHumidity() {
		return mSharedPreferences.getInt("minEarthHumidity",MIN_SOIL_H);
	}
	public void setMinEarthHumidity(int minEarthHumidity) {
		saveIntValueToPreferences("minEarthHumidity", minEarthHumidity);
	}

	//土壤湿度最大值
	public int getMaxEarthHumidity() {
		return mSharedPreferences.getInt("maxEarthHumidity",MAX_SOIL_H);
	}
	public void setMaxEarthHumidity(int maxEarthHumidity) {
		saveIntValueToPreferences("maxEarthHumidity", maxEarthHumidity);
	}

	//灯光强度最小值
	public int getMinLight() {
		return mSharedPreferences.getInt("minLight",MIN_LIGHT);
	}
	public void setMinLight(int minLight) {
		saveIntValueToPreferences("minLight", minLight);
	}

	//灯光强度最大值
	public int getMaxLight() {
		return mSharedPreferences.getInt("maxLight",MAX_LIGHT);
	}
	public void setMaxLight(int maxLight) {
		saveIntValueToPreferences("maxLight", maxLight);
	}

	//CO2浓度最小值
	public int getMinCo2() {
		return mSharedPreferences.getInt("minCo2",MIN_CO2);
	}
	public void setMinCo2(int minCo2) {
		saveIntValueToPreferences("minCo2", minCo2);
	}

	//CO2浓度最大值
	public int getMaxCo2() {
		return mSharedPreferences.getInt("maxCo2",MAX_CO2);
	}
	public void setMaxCo2(int maxCo2) {
		saveIntValueToPreferences("maxCo2", maxCo2);
	}

	//PM2.5浓度最大值
	public int getMaxPm25() {
		return mSharedPreferences.getInt("maxPm25",MAX_PM25);
	}
	public void setMaxPm25(int maxPm25) {
		saveIntValueToPreferences("maxPm25", maxPm25);
	}
	
	//警告控制，0表示手动控制，1表示自动控制
	public int getControlAuto() {
		return mSharedPreferences.getInt("controlAuto",CONTROL_AUTO);
	}
	public void setControlAuto(int controlAuto) {
		saveIntValueToPreferences("controlAuto", controlAuto);
	}
	
}